package work.lianbiao;

import work.ListNode;

public class Problem160 {


    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        ListNode A = headA;
        ListNode B = headB;
        while (A != B) {
            A = A != null ? A.next : headB;
            B = B != null ? B.next : headA;
        }
        return A;
    }

    ;


    public static void main(String[] args) {

    }

    public ListNode getIntersectionNode1(ListNode headA, ListNode headB) {
        ListNode A = headA;
        ListNode B = headB;
        while (A != B) {
            if (A == null) A = headB;
            else if (B == null) B = headA;
            else {
                B = B.next;
                A = A.next;
            }
        }
        return A;
    }


}
